/*
 * The class controls the players inventory
 */
public class InventoryController {
	InventoryModel model = new InventoryModel();
	InventoryView view = new InventoryView();

	public InventoryController(InventoryModel model, InventoryView view) {
		this.model = model;
		this.view = view;
	}

	/*
	 * adds an Item to the arrayList of items, increments the weight of the
	 * wagon.
	 */
	public void addNewItem(String type, int quantity) {
		Item newItem = new Item(type, quantity);
		model.getItems().add(newItem);
		double weight = newItem.getWeight();
		model.setTotalLbs(model.getTotalLbs() + weight);

	}

	/*
	 * Deletes the item from arraylist and decrements the total weight
	 */
	public void deleteItem(String type, int quantity) {
		for (int i = 0; i <= model.getItems().size(); i++) {
			if (model.getItems().get(i).getType() == type) {
				double weight = model.getItems().get(i).getWeight();
				model.getItems().remove(i);
				model.setTotalLbs(model.getTotalLbs() - weight);
			}
		}
	}

	// increases the quantity of the particular item in the arrayList and also
	// increases the total weight of wagon.
	public void incrementQuantityOfItem(String type,int quantity) {
		for (int i = 0; i < model.getItems().size(); i++) {
			if (model.getItems().get(i).getType() == type) {
				model.getItems().get(i).setQuantity(
						(model.getItems().get(i).getQuantity()) + quantity);
				double itemWeight = model.getItems().get(i).getWeight();
				model.setTotalLbs(model.getTotalLbs() + itemWeight);
			}
		}
	}

	/*
	 * Decreases the quantity of that particular object and also decreases the
	 * total weight of the wagon
	 */
	public void decrementQuantityOfItem(String type, int quantity) {
		for (int i = 0; i < model.getItems().size(); i++) {
			if (model.getItems().get(i).getType() == type) {
				model.getItems().get(i).setQuantity(
						(model.getItems().get(i).getQuantity()) - quantity);
				double itemWeight = model.getItems().get(i).getWeight();
				model.setTotalLbs(model.getTotalLbs() - itemWeight);
			}

		}
	}

	public String getQuantityOfItem(String type) {
		for (int i = 0; i < model.getItems().size(); i++) {
			if (model.getItems().get(i).getType() == type) {
				return model.getItems().get(i).getQuantity()+"";
			}
		}
			return null;
	}

	
}
